import {
	search_read
} from "./apibase.js";
import store from "@/store";
// 产品列表
export const productList = (params) => {
	let domain = [];
	params.keyword && domain.push(['name', 'like', params.keyword]);
	params.team_id && domain.push(['team_id', '=', params.team_id]);
	return search_read({
		model: 'finished.product',
		fields: ['photo', 'name', 'has_aluminum_backing', 'trim', 'backing_type'],
		domain,
		limit: params.limit,
		offset: params.offset,
	});
}
// 产品详情
export const productDetail = (params) => {
	return search_read({
		model: 'finished.product',
		fields: [],
		domain: [
			["id", "=", params.id]
		],
		limit: 0,
		offset: 0,
	});
}
// 客户列表
export const getCustomerList = (params) => {
	let domain = [
		["is_company", "=", "true"]
	];
	params.keyword && domain.push(['name', 'like', params.keyword]);
	return search_read({
		model: 'res.partner',
		fields: ['avatar_256', 'name', 'company_id', 'mobile'],
		domain,
		limit: params.limit,
		offset: params.offset,
	});
}
// 公司列表
export const getCompanyList = (params) => {
	return search_read({
		model: 'res.company',
		fields: ['id', 'name'],
		domain: [],
		limit: 0,
		offset: 0,
	});
}
// 客户详情
export const getCustomerDetail = (params) => {
	return search_read({
		model: 'res.partner',
		fields: ['avatar_256', 'name', 'mobile', 'company_id', 'function'],
		domain: [
			["id", "=", params.id]
		],
		limit: 0,
		offset: 0,
	});
}
// 收货地区
export const receivingRegion = () => {
	return search_read({
		model: 'quotation.freight',
		limit: 0,
		offset: 0,
	});
}
// 用户信息
export const userInfo = () => {
	let user_context = store.state.user_context;
	user_context = JSON.parse(user_context || '{}');
	return search_read({
		model: 'hr.employee',
		fields: ['id', 'name', 'mobile_phone', 'company_id', 'avatar_256', 'department_id'],
		domain: [
			["user_id", "=", user_context.uid]
		],
		limit: 0,
		offset: 0,
	});
}
// 用户权限
export const userAuth = () => {
	let user_context = store.state.user_context;
	user_context = JSON.parse(user_context || '{}');
	return search_read({
		model: 'res.users',
		fields: ['name', 'phone', 'mobile_phone', 'company_id', 'avatar_256', 'department_id',
			'enable_mobile_customer', 'crm_team_ids'
		],
		domain: [
			["id", "=", user_context.uid]
		],
		limit: 0,
		offset: 0,
	});
}
// 报价记录列表
export const quotationRecordList = (params) => {
	let user_context = store.state.user_context;
	user_context = JSON.parse(user_context || '{}');
	return search_read({
		model: 'sale.quotation',
		fields: ['image_256', 'product_id', 'amount', 'quantity', 'create_date'],
		domain: [
			['user_id', "=", user_context.uid],
			['state', "!=", 'draft']
		],
		limit: params.limit,
		offset: params.offset,
	});
}
// 商机记录列表
export const previewRecordList = (params) => {
	let user_context = store.state.user_context;
	user_context = JSON.parse(user_context || '{}');
	return search_read({
		model: 'sale.quotation',
		fields: ['image_256', 'product_id', 'amount', 'quantity', 'create_date'],
		domain: [
			['user_id', "=", user_context.uid],
			['state', "=", 'order'],
			['partner_id', "=", Number(params.customer_id)],
		],
		limit: params.limit,
		offset: params.offset,
	});
}
// 报价记录详情
// export const quotationRecordDetail = (params) => {
// 	return search_read({
// 		model: 'sale.quotation',
// 		domain: [
// 			["id", "=", params.id]
// 		],
// 		limit: 0,
// 		offset: 0,
// 	});
// }

// 税率列表(picker)
export const getTaxsPicker = (params) => {
	return search_read({
		model: 'quotation.tax',
		fields: ['id', 'name'],
		domain: [],
		limit: 0,
		offset: 0,
	});
}

// 渠道分类
export const crmTeam = (params) => {
	return search_read({
		model: 'crm.team',
		fields: ['id', 'name'],
		domain: [
			['id', 'in', params.crm_team_ids],
		],
		limit: 0,
		offset: 0,
	});
}